import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		int s1 = 0;
		int s2 = 0;
		for(int i = 1; i <= 9; i ++ ) {
			s1 += sc.nextInt();
		}
		for(int i = 1; i <= 8; i ++ ) {
			s2 += sc.nextInt();
		}
		if(s2 > s1) {
			System.out.print(0);
		} else {
			System.out.print(s1 - s2 + 1);
		}
	}
}
